package com.chuangke.common.utils;

import java.lang.management.ManagementFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 日期时间相关工具
 *
 * @author chuangke
 * @date Sep 23, 2018
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {

    public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String DAY_FORMAT = "yyyyMMdd";

    /**
     * 获取当前标准格式化日期时间
     *
     * @return
     */
    public static String getDateTime() {
        return getDateTime(new Date());
    }

    /**
     * 标准格式化日期时间
     *
     * @param date
     * @return
     */
    public static String getDateTime(Date date) {
        return (new SimpleDateFormat(DATE_FORMAT)).format(date);
    }

    /**
     * 日期字符串生成指定格式的日期
     *
     * @param strDate
     * @param formate
     * @return
     */
    public static Date getDate(String strDate, String formate) {
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat(formate);
        try {
            date = sdf.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 日期生成指定格式的日期字符串
     *
     * @param date
     * @param formate
     * @return
     */
    public static String getDate(Date date, String formate) {
        SimpleDateFormat sdf = new SimpleDateFormat(formate);
        return sdf.format(date);
    }

    /**
     * 给定格式的日期串生成指定格式的日期字符串
     *
     * @param date
     * @param srcFormate
     * @param distFormate
     * @return
     */
    public static String getDateStr(String date, String srcFormate, String distFormate) {
        return getDate(getDate(date, srcFormate), distFormate);
    }

    /**
     * @param date
     * @param formate
     * @param field   (Calendar.YEAR, Calendar.MONTH, Calendar.DATE)
     * @param amount
     * @return
     */
    public static String add(Date date, String formate, int field, int amount) {
        Date d = add(date, field, amount);
        return getDate(d, formate);
    }

    public static Date add(Date date, int field, int amount) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(field, amount);
        return c.getTime();
    }

    /**
     * @param date
     * @return
     */
    public static double calMonthDayBitYearDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        double monthDays = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        double yearDays = c.getActualMaximum(Calendar.DAY_OF_YEAR);
        return monthDays / yearDays;
        // BigDecimal b = new BigDecimal(monthDays/yearDays);
        // return b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    /**
     * 得到上个月
     *
     * @param date
     * @return
     */
    public static String previousMonth(String date) {
        switch (date.length()) {
            case 8:
                date = date.substring(0, 6);
            case 5:
                date = date.substring(0, 4) + "0" + date.substring(4);
        }
        String formate = "yyyyMM";
        Date date1 = getDate(date, formate);
        return add(date1, formate, Calendar.MONTH, -1);
    }

    public static String previousMonth(Date date) {
        return add(date, "yyyyMM", Calendar.MONTH, -1);
    }

    /**
     * 得到下一月
     *
     * @param date
     * @return
     */
    public static String nextMonth(String date) {
        String formate = "yyyyMM";
        Date date1 = getDate(date, formate);
        return add(date1, formate, Calendar.MONTH, 1);
    }

    /**
     * 得到上一年
     *
     * @param date
     * @return
     */
    public static String previousYear(String date) {
        String formate = "yyyy";
        Date date1 = getDate(date, formate);
        return add(date1, formate, Calendar.YEAR, -1);
    }

    /**
     * 得到下一年
     *
     * @param date
     * @return
     */
    public static String nextYear(String date) {
        String formate = "yyyy";
        Date date1 = getDate(date, formate);
        return add(date1, formate, Calendar.YEAR, 1);
    }

    public static int getDifDay(String startDate, String endDate) {
        String formate = "yyyyMMdd";
        return getDifDay(getDate(startDate, formate), getDate(endDate, formate));
    }

    public static int getDifDay(Date startDate, Date endDate) {
        long start = startDate.getTime();
        long end = endDate.getTime();

        // 需要计算运行天数时，计算差值
        long days = (end - start) / (1000 * 60 * 60 * 24);
        // 运行天数从1开始计数
        long runningDays = days + 1;

        // // 判断是否跨天，若跨天，运行天数还要+1
        // long probableEndMillis = start + (1000 * 60 * 60 * 24) * days;
        // if (new Date(probableEndMillis).getDay() != new Date(end).getDay()) {
        // runningDays++;
        // }
        return Math.round(runningDays);
    }

    /**
     * 计算两个月份之间相差的月份数
     *
     * @param startDate
     * @param endDate
     * @return
     */
    public static Integer getDifMonth(Date startDate, Date endDate) {
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        start.setTime(startDate);
        end.setTime(endDate);
        int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
        int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
        return Math.abs(month + result);
    }

    public static double calTime(String start, String end) {
        String formate = "yyyyMMddHHmmss";
        SimpleDateFormat sdf = new SimpleDateFormat(formate);
        Date startDate = null, endDate = null;
        try {
            startDate = sdf.parse(start);
            endDate = sdf.parse(end);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long l = endDate.getTime() - startDate.getTime();
        long day = l / (24 * 60 * 60 * 1000);
        long hour = l / (60 * 60 * 1000);
        double min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);

        double time = (hour + day * 24) + min / 60;
        BigDecimal t = new BigDecimal(time);
        return t.setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

    /**
     * 取得季度第一天
     *
     * @return
     */
    public static String getFirstDateOfSeason(String dateStr, String srcFormate, String distFormate) {
        Date date = getDate(dateStr, srcFormate);
        Date firstDate = getFirstDateOfMonth(getSeasonDate(date)[0]);

        return getDate(firstDate, distFormate);
    }

    /**
     * 取得月第一天
     *
     * @param date
     * @return
     */
    public static Date getFirstDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 取得季度最后一天
     *
     * @return
     */
    public static String getLastDateOfSeason(String dateStr, String srcFormate, String distFormate) {
        Date date = getDate(dateStr, srcFormate);
        Date lastDate = getLastDateOfMonth(getSeasonDate(date)[2]);

        return getDate(lastDate, distFormate);
    }

    /**
     * 取得月最后一天
     *
     * @param date
     * @return
     */
    public static Date getLastDateOfMonth(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
        return c.getTime();
    }

    /**
     * 获取当前周的第一天
     *
     * @return
     */
    public static Date getWeekStartDate() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        return cal.getTime();
    }

    /**
     * 得到一个月的最后一天
     *
     * @param date
     * @return
     */
    public static String getLastDateOfMonth(String date) {
        return getDate(getLastDateOfMonth(getDate(date, "yyyyMM")), "yyyyMMdd");
    }

    /**
     * 取得季度月
     *
     * @param date
     * @return
     */
    public static Date[] getSeasonDate(Date date) {
        Date[] season = new Date[3];

        Calendar c = Calendar.getInstance();
        c.setTime(date);

        int nSeason = getSeason(date);
        if (nSeason == 1) {// 第一季度
            c.set(Calendar.MONTH, Calendar.JANUARY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.FEBRUARY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MARCH);
            season[2] = c.getTime();
        } else if (nSeason == 2) {// 第二季度
            c.set(Calendar.MONTH, Calendar.APRIL);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.MAY);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.JUNE);
            season[2] = c.getTime();
        } else if (nSeason == 3) {// 第三季度
            c.set(Calendar.MONTH, Calendar.JULY);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.AUGUST);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.SEPTEMBER);
            season[2] = c.getTime();
        } else if (nSeason == 4) {// 第四季度
            c.set(Calendar.MONTH, Calendar.OCTOBER);
            season[0] = c.getTime();
            c.set(Calendar.MONTH, Calendar.NOVEMBER);
            season[1] = c.getTime();
            c.set(Calendar.MONTH, Calendar.DECEMBER);
            season[2] = c.getTime();
        }
        return season;
    }

    /**
     * 1 第一季度 2 第二季度 3 第三季度 4 第四季度
     *
     * @param date
     */
    public static int getSeason(Date date) {

        int season = 0;

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        int month = c.get(Calendar.MONTH);
        switch (month) {
            case Calendar.JANUARY:
            case Calendar.FEBRUARY:
            case Calendar.MARCH:
                season = 1;
                break;
            case Calendar.APRIL:
            case Calendar.MAY:
            case Calendar.JUNE:
                season = 2;
                break;
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.SEPTEMBER:
                season = 3;
                break;
            case Calendar.OCTOBER:
            case Calendar.NOVEMBER:
            case Calendar.DECEMBER:
                season = 4;
                break;
            default:
                break;
        }
        return season;
    }

    /**
     * 获取某个月的天数
     *
     * @param date
     * @return
     */
    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    public static List<String> getDays(String start, String end, String formate) {
        List<String> days = new LinkedList<>();

        DateFormat dateFormat = new SimpleDateFormat(formate);
        try {
            Date startDate = dateFormat.parse(start);
            Date endDate = dateFormat.parse(end);

            Calendar tempStart = Calendar.getInstance();
            tempStart.setTime(startDate);

            Calendar tempEnd = Calendar.getInstance();
            tempEnd.setTime(endDate);
            tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
            while (tempStart.before(tempEnd)) {
                days.add(dateFormat.format(tempStart.getTime()));
                tempStart.add(Calendar.DAY_OF_YEAR, 1);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return days;
    }

    public static String formate(String date) {
        if (date == null) {
            return null;
        }
        if (date.length() == 6) {
            return date.substring(0, 4) + "-" + date.substring(4, 6);
        }

        if (date.length() == 8) {
            return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
        }
        return date;
    }

    public static int getAgeByBirth(Date birthDay) {
        int age = 0;
        Calendar cal = Calendar.getInstance();
        if (cal.before(birthDay)) { // 出生日期晚于当前时间，无法计算
            throw new IllegalArgumentException("The birthDay is before Now.It's unbelievable!");
        }
        int yearNow = cal.get(Calendar.YEAR); // 当前年份
        int monthNow = cal.get(Calendar.MONTH); // 当前月份
        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH); // 当前日期
        cal.setTime(birthDay);
        int yearBirth = cal.get(Calendar.YEAR);
        int monthBirth = cal.get(Calendar.MONTH);
        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
        age = yearNow - yearBirth; // 计算整岁数
        if (monthNow <= monthBirth) {
            if (monthNow == monthBirth) {
                if (dayOfMonthNow < dayOfMonthBirth)
                    age--;// 当前日期在生日之前，年龄减一
            } else {
                age--;// 当前月份在生日之前，年龄减一
            }
        }
        return age;

    }

    /**
     *     * 获取两个日期相差的月数     * @param d2  较大的日期     * @param d1  较小的日期     * @return
     * 如果d1>d2返回 月数差 否则返回0    
     */
    public static int getMonthDiff(Date date1, Date date2) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();

        // 将String日期转换成date

        c1.setTime(date1);
        c2.setTime(date2);

        // 判断两个日期的大小

        if (c2.getTimeInMillis() < c1.getTimeInMillis())
            return 0;
        int year1 = c1.get(Calendar.YEAR);
        int year2 = c2.get(Calendar.YEAR);
        int month1 = c1.get(Calendar.MONTH);
        int month2 = c2.get(Calendar.MONTH);
        int day1 = c1.get(Calendar.DAY_OF_MONTH);
        int day2 = c2.get(Calendar.DAY_OF_MONTH);
        // 获取年的差值 假设 d1 = 2015-9-30   d2 = 2015-12-16
        int yearInterval = year2 - year1;
        // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
        if (month2 < month1 || month1 == month2 && day2 < day1)
            yearInterval--;
        // 获取月数差值
        int monthInterval = (month2 + 12) - month1;
        if (day2 > day1)
            monthInterval++;
        monthInterval %= 12;
        return yearInterval * 12 + monthInterval;
    }

    /**
     * 日期格式修正
     *
     * @param date
     * @return 返回纯数字日期
     */
    public static String correctDate(String date) {
        if (date == null || date.isEmpty()) {
            return date;
        }

        String[] dd = date.split("[-|/]");

        StringBuilder dateStr = new StringBuilder();
        for (int i = 0; i < dd.length; i++) {
            if (i == 0) {
                dateStr.append(StrUtil.fillBefore(dd[i], '0', 4));
            }
            if (i == 1 || i == 2) {
                dateStr.append(StrUtil.fillBefore(dd[i], '0', 2));
            }

        }
        return dateStr.toString();
    }

    /**
     * 获取一个期间内的所有月份
     * @param startMonth
     * @param endMonth
     * @return
     */
    public static List<String> getMonths(String startMonth, String endMonth) {
        if (startMonth.compareTo(endMonth) > 0) {
            return new ArrayList<>();
        }

        List<String> months = new ArrayList<>();
        months.add(startMonth);
        String month = startMonth;
        while (month.compareTo(endMonth) < 0) {
            month = nextMonth(month);
            months.add(month);
        }
        return months;
    }

    public static List<String> getYears(String startYear, String endYear) {
        if (startYear.compareTo(endYear) > 0) {
            return new ArrayList<>();
        }

        List<String> years = new ArrayList<>();
        years.add(startYear);
        String year = startYear;
        while (year.compareTo(endYear) < 0) {
            year = nextYear(year);
            years.add(year);
        }
        return years;
    }

    public static BigDecimal getAge(Date birthday) {
        BigDecimal ageMonth = new BigDecimal(DateUtils.getMonthDiff(birthday, new Date()));
        return ageMonth.divide(new BigDecimal("12"), 1, RoundingMode.HALF_UP);
    }

    public static String getBirthdayById(String cardId) {
        return cardId.substring(6, 14);
    }

    /**
     * 获取服务器启动时间
     */
    public static Date getServerStartDate() {
        long time = ManagementFactory.getRuntimeMXBean().getStartTime();
        return new Date(time);
    }

    /**
     * 获取当前Date型日期
     *
     * @return Date() 当前日期
     */
    public static Date getNowDate() {
        return new Date();
    }
    
    public static long getHourDiff(Date startDate, Date endDate) {
    	long nh = 1000 * 60 * 60 ;
    	long diff = endDate.getTime()-startDate.getTime();
        // 计算差多少各小时
        return diff / nh;
    }
    /**
     * 计算两个时间差
     */
    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟";
    }

    public static int getWeekByDate(String date, String formate) {
        Date ddate = DateUtils.getDate(date, formate);
        return getWeekByDate(ddate);
    }

    public static int getWeekByDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.WEEK_OF_YEAR);
    }

    /**
     * 获取某年某月开始日期
     *
     * @return String
     **/
    public static String getMonthStart(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        Date time = cal.getTime();
        return new SimpleDateFormat(DAY_FORMAT).format(time);
    }

    /**
     * 获取某年某月最后一天
     *
     * @return String
     **/
    public static String getMonthEnd(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        Date time = cal.getTime();
        return new SimpleDateFormat(DAY_FORMAT).format(time);
    }

    /**
     * 获取本周的第一天
     *
     * @return String
     **/
    public static String getWeekStart() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.WEEK_OF_MONTH, 0);
        cal.set(Calendar.DAY_OF_WEEK, 2);
        Date time = cal.getTime();
        return new SimpleDateFormat(DAY_FORMAT).format(time);
    }

    /**
     * 获取本周的最后一天
     *
     * @return String
     **/
    public static String getWeekEnd() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
        cal.add(Calendar.DAY_OF_WEEK, 1);
        Date time = cal.getTime();
        return new SimpleDateFormat(DAY_FORMAT).format(time);
    }

    /**
     * 获取某年的第一天
     *
     * @return String
     **/
    public static String getYearStart(int year) {
        return year + "0101";
    }

    /**
     * 获取某年的最后一天
     *
     * @return String
     **/
    public static String getYearEnd(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        Date currYearLast = calendar.getTime();
        return new SimpleDateFormat(DAY_FORMAT).format(currYearLast);
    }

    /**
     * 获取某年某周的时间跨度
     *
     * @param year
     * @param week
     * @return
     */
    public static Map<String, String> getWeekRangeMap(int year, int week) {
        Map<String, String> timeMap = new HashMap<>();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.setFirstDayOfWeek(Calendar.MONDAY);// 设置星期一为一周开始的第一天
        calendar.setMinimalDaysInFirstWeek(4);// 可以不用设置
        int weekYear = calendar.get(Calendar.YEAR);// 获得当前的年
        calendar.setWeekDate(weekYear, week, 2);// 获得指定年的第几周的开始日期
        Date time = calendar.getTime();
        String startDate = new SimpleDateFormat(DAY_FORMAT).format(time);
        timeMap.put("startDate", startDate);
        calendar.setWeekDate(weekYear, week, 1);// 获得指定年的第几周的结束日期
        time = calendar.getTime();
        String endDate = new SimpleDateFormat(DAY_FORMAT).format(time);
        timeMap.put("endDate", endDate);
        return timeMap;
    }

    /**
     * 获取某年某月的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, String> getMonthRangeMap(int year, int month) {
        Map<String, String> timeMap = new HashMap<>();
        timeMap.put("startDate", getMonthStart(year, month));
        timeMap.put("endDate", getMonthEnd(year, month));
        return timeMap;
    }

    /**
     * 获取某年某季的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, String> getQuarterRangeMap(int year, int quarter) {
        int startMonth = quarter * 3 - 2;
        int endMonth = quarter * 3;
        Map<String, String> timeMap = new HashMap<>();
        timeMap.put("startDate", getMonthStart(year, startMonth));
        timeMap.put("endDate", getMonthEnd(year, endMonth));
        return timeMap;
    }

    /**
     * 获取某年某季的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, String> getHalfYearRangeMap(int year, int halfYear) {
        int startMonth = halfYear * 6 - 5;
        int endMonth = halfYear * 6;
        Map<String, String> timeMap = new HashMap<>();
        timeMap.put("startDate", getMonthStart(year, startMonth));
        timeMap.put("endDate", getMonthEnd(year, endMonth));
        return timeMap;
    }

    /**
     * 获取某年的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, String> getYearRangeMap(int year) {
        Map<String, String> timeMap = new HashMap<>();
        timeMap.put("startDate", getYearStart(year));
        timeMap.put("endDate", getYearEnd(year));
        return timeMap;
    }

    /**
     * 获取某年有多少周
     *
     * @param year
     * @return
     * @throws ParseException
     */
    public static int getYearWeekConut(int year) {
        int week = 52;
        try {
            Map<String, String> timeMap = getWeekRangeMap(year, 53);
            if (!CollectionUtils.isEmpty(timeMap)) {
                String startDate = timeMap.get("startDate");
                if (startDate.substring(0, 4).equals(year + "")) { // 判断年度是否相符，如果相符说明有53个周。
                    week = 53;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return week;
    }

    /**
     * 获取某年所有周的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getYearWeekMap(int year) {
        int weeks = getYearWeekConut(year);
        Map<String, Map<String, String>> yearWeekMap = new HashMap<>();
        for (int i = 1; i <= weeks; i++) {
            Map<String, String> timeMap = getWeekRangeMap(year, i);
            yearWeekMap.put(i + "", timeMap);
        }
        return yearWeekMap;
    }

    /**
     * 获取某年所有月的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getYearMonthMap(int year) {
        Map<String, Map<String, String>> yearMonthMap = new HashMap<>();
        for (int i = 1; i <= 12; i++) {
            Map<String, String> timeMap = getMonthRangeMap(year, i);
            yearMonthMap.put(i + "", timeMap);
        }
        return yearMonthMap;
    }

    /**
     * 获取某年所有季的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getYearQuarterMap(int year) {
        Map<String, Map<String, String>> yearQuarterMap = new HashMap<>();
        for (int i = 1; i <= 4; i++) {
            Map<String, String> timeMap = getQuarterRangeMap(year, i);
            yearQuarterMap.put(i + "", timeMap);
        }
        return yearQuarterMap;
    }

    /**
     * 获取某年所有半年的时间跨度
     *
     * @param year
     * @return
     */
    public static Map<String, Map<String, String>> getHalfYearMap(int year) {
        Map<String, Map<String, String>> halfYearMap = new HashMap<>();
        for (int i = 1; i <= 2; i++) {
            Map<String, String> timeMap = getHalfYearRangeMap(year, i);
            halfYearMap.put(i + "", timeMap);
        }
        return halfYearMap;
    }
    
    /**
     * 获取季度的倒数第几天
     * @param date
     * @param amount
     * @return
     */
    public static Date getEndOfQuarter(Date date,int amount) {
    	DateTime lastQuarterDateTime = DateUtil.endOfQuarter(date) ;
		Date lastQuarterDate = lastQuarterDateTime.toJdkDate() ;
		return DateUtils.addDays(lastQuarterDate, amount) ;
    }
    
    public static Date getEndOfMonth(Date date,int amount) {
    	DateTime lastMonthDateTime = DateUtil.endOfMonth(date) ;
		Date lastMonthDate = lastMonthDateTime.toJdkDate() ;
		return DateUtils.addDays(lastMonthDate, amount) ;
    }
    
    public static Date getEndOfWeek(Date date,int amount) {
    	DateTime lastWeekDateTime = DateUtil.endOfWeek(date) ;
		Date lastWeekDate = lastWeekDateTime.toJdkDate() ;
		return DateUtils.addDays(lastWeekDate, amount) ;
    }
    

    public static void main(String[] args) {
//		List<String> months = getMonths("201901", "202003");
//		System.out.println(months);
//		System.out.println(getYears("2013", "2013"));

        System.out.println(getBirthdayById("37131219861123693x"));

//		DateUtils.getDate("20195433", "yyyyMMdd");

//		String id = "372429197109040017";
//		System.out.println(getAgeByBirth(getDate(id.substring(6, 14), "yyyyMMdd")));
//		System.out.println(getMonthDiff(getDate("20190106", "yyyyMMdd"),new Date()));

//		System.out.println(getDifMonth(getDate("201903", "yyyyMM"), getDate("201902", "yyyyMM")) + 1);
        
        Date d1 = DateUtils.getDate("202305201512", "yyyyMMddHHmm") ;
        Date d2 = new Date() ;
//        System.out.println(getHourDiff(d2,d1)) ;
//        System.out.println(d2.compareTo(d1)) ;
        System.out.println(DateUtils.getDate(new Date(), "yyyy年M月d日")) ;
    }

}
